#ifndef _RBSTROM_H
#define _RBSTROM_H

#include <stdlib.h>

template <class T>
class RBuzel
 {private:
    RBuzel<T> *l,*p,*o;
    char cerveny,levy;
    T u;
  public:
    RBuzel(T v){ o=l=p=NULL; cerveny=1; levy=0; u=v; }
    ~RBuzel(){ if(l) delete l; if(p) delete p; }
    RBuzel<T>* O() {return o;}
    RBuzel<T>* L() {return l;}
    RBuzel<T>* P() {return p;}
    void O(RBuzel<T> *u) {o=u;}
    void L(RBuzel<T> *u) {l=u; if(u) {u->O(this); u->lS(1);} }
    void P(RBuzel<T> *u) {p=u; if(u) {u->O(this); u->lS(0);} }
    int lS() {return levy;}
    void lS(char lv) {levy=lv;}
    int C() {return cerveny;}
    void zmenC() {cerveny=1-cerveny;}
    T U() {return u;}
    void U(T v) {u=v;}
 };

template <class T>
class RBstrom //cerveno-cerny strom
 {private:
    typedef long(*Cmp)(T,T);
    Cmp cmp;
    RBuzel<T> *t;
  public:
    RBstrom(Cmp cp) { t=NULL; cmp=cp; }
    ~RBstrom() { if(t) delete t; }
    T pridej(T);
    int uber(T);
 };

//#include "rbstrom.cc"

#endif
